<template>
	<view class="tabs">
		<view class="tab-bar">
			<view class="tab-bar-item" v-for="(item,index) in tabList" :key="index" @click="ontabchange(index)">
				<text class="uni-tab-item-title"
					:class="tabIndex==index ? 'uni-tab-item-title-active' : ''">{{item.label}}</text>
				<text class="uni-tab-item-border" v-if="tabIndex==index"></text>
				<label class="new-tag" v-if="item.isNew"></label>
			</view>
		</view>
		<view class="feedback-form" v-if="tabIndex==0">
			<uni-easyinput class="feedback-form-item" type="textarea" v-model="formData.content" :inputBorder="false"
				:placeholderStyle="placeholderStyle" placeholder="有什么意见，尽管告诉我们吧！" maxlength="200">
			</uni-easyinput>
			<uni-easyinput class="feedback-form-item" type="text" autoHeight v-model="formData.contact" :inputBorder="false"
				:placeholderStyle="placeholderStyle" placeholder="请留下您的邮箱/手机号">
			</uni-easyinput>
			<button type="default" :disabled="disabled" class="submit-btn" @click="onSubmitClick">提交留言</button>
		</view>
		<scroll-view v-if="tabIndex==1" class="scroll-v list" enableBackToTop="true" scroll-y @scrolltolower="loadMore">
			<view class="list-empty" v-if="feedbackList.length==0">
				<image class="list-empty-bg" src="../../static/images/img_evaluate_empty_bg@3x.png"></image>
				<label class="list-empty-label">暂无记录</label>
			</view>
			<view v-else v-for="(item,index) in feedbackList" :key="index">
				<view class="feedback-item" @click="goDetail(item.id)">
					<label class="feedback-item-time">{{item.time}}</label>
					<label class="feedback-item-content">{{item.content}}</label>
				</view>
			</view>
			<view class="loading-more" v-if="feedbackList.length > 4">
				<text class="loading-more-text">加载更多...</text>
			</view>
		</scroll-view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				tabIndex: 0, //当前选中index
				tabList: [{
					id: 0,
					index: "class_" + 0,
					label: "提交反馈",
				}, {
					id: 1,
					index: "class_" + 1,
					label: "我的反馈"
				}],
				disabled:false,
				placeholderStyle:"font-size:28rpx;color:#acacac",
				formData:{},
				feedbackList:[]
			}
		},
		onLoad(option) {
			if(option && option.tab){
				this.tabIndex = option.tab;
				this.getFeedbackList()
			}
		},
		methods: {
			ontabchange(index){
				this.tabIndex = index;
				if(index==1){
					this.getFeedbackList()
				}
			},
			onSubmitClick(){
				if(!this.formData.content){
					uni.showToast({
						icon: "none",
						title: "请输入反馈意见"
					})
					return;
				}
				console.log("提交成功")
				uni.redirectTo({
					url:"./feedbackSuccess"
				})
			},
			getFeedbackList() {
				for (let i = 0; i < 10; i++) {
					this.feedbackList.push({
						id:i,
						time:"2021-05-06",
						content:"这是反馈文字内容这是反馈文字内容这是反馈文这是反馈文字内容这是反馈文字内容这是反馈文"
					})
				}
				this.$forceUpdate()
			},
			goDetail(id) {
				uni.navigateTo({
					url: './feedbackDetail?id=' + id
				});
			},
			loadMore(e) {
				setTimeout(() => {
					this.getFeedbackList(this.tabIndex);
				}, 500)
			}
		}
	}
</script>

<style>
	page {
		width: 100%;
		min-height: 100%;
		display: flex;
	}
	.tabs {
		display: flex;
		flex-direction: column;
		width: 100%;
	}

	.tab-bar {
		margin: 32rpx 0;
		display: flex;
		flex-wrap: nowrap;
		align-items: center;
		justify-content: space-evenly;
	}

	.tab-bar-item {
		display: flex;
		flex-flow: column;
		align-items: center;
	}

	.uni-tab-item-title {
		color: #7B7B7B;
		font-size: 30rpx;
		margin-bottom: 10rpx;
		flex-wrap: nowrap;
		/* #ifndef APP-PLUS */
		white-space: nowrap;
		/* #endif */
	}

	.uni-tab-item-title-active {
		color: #181818;
		font-size: 30rpx;
		font-weight: 500;
	}

	.uni-tab-item-border {
		width: 36rpx;
		height: 2rpx;
		background-color: #1371FF;
		display: block;
		margin: 0 auto;
	}
	.feedback-form{
		display: flex;
		flex-flow: column;
		
	}
	.feedback-form-item{
		margin: 0 32rpx;
		background-color: #F4F4F4;
		border-radius: 16rpx;
		padding: 32rpx;
		margin-bottom: 24rpx;
	}
	.uni-easyinput__content{
		min-height: inherit !important
	}
	.submit-btn{
		margin-top: 40rpx !important;
	}
	.scroll-v {
		display: flex;
		flex: 1;
	}
	.feedback-item{
		display: flex;
		flex-flow: column;
		padding: 32rpx;
		margin: 32rpx 32rpx 24rpx 32rpx;
		background-color: #F4F4F4;
		border-radius: 16rpx;
	}
	.feedback-item-time{
		margin-bottom: 10rpx;
		font-size: 32rpx;
		color: #333333;
	}
	.feedback-item-content{
		width: 100%;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		font-size: 28rpx;
		color: #7B7B7B;
	}
	.loading-icon {
		width: 20rpx;
		height: 20rpx;
		margin-right: 5rpx;
		color: #999999;
	}

	.loading-text {
		margin-left: 2rpx;
		font-size: 16rpx;
		color: #999999;
	}

	.list-empty {
		background-color: #FFFFFF;
		border-radius: 16rpx 16rpx 0px 0px;
		text-align: center;
		padding-top: 48rpx;
		padding-bottom: 88rpx;
		width: 100%;
		position: absolute;
		top: 20%;
	}

	.list-empty-bg {
		width: 420rpx;
		height: 300rpx;
		display: block;
		margin: 0 auto 30rpx auto;
	}

	.list-empty-label {
		font-size: 22rpx;
		color: #ACACAC;
	}
</style>
